package vn.sunnet.backviet01.game.coloa.human.enemy;

import java.util.Timer;
import java.util.TimerTask;

import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

import vn.sunnet.backviet01.game.coloa.interfaces.MyGeneral;

public class MinisterEnemy extends Enemy implements MyGeneral{
	protected float mana;
	protected float HPps;

	private MinisterCoolDown timeRecoverHP = null;
	
	public MinisterEnemy(int tiledAttack, float pX, float pY,
			TiledTextureRegion pTiledTextureRegion) {
		super(tiledAttack, pX, pY, pTiledTextureRegion);
		setCoolDownRecoverHP(1000);
	}

	public void setStreng(float streng) {
		this.streng = streng + STRENG_DEFAULT;
		this.hitPoints = this.streng * 25;
		HPps = streng / 4;
		mTotalHitPoint = hitPoints;
	}

	public float getStreng() {
		return streng;
	}

	public void setAgility(float agility) {
		this.agility = agility + AGILITY_DEFAULT;
		this.armour = (float)Math.ceil(this.agility * 0.5f);
		if (armour > 100)
			armour = 100;
	}

	public float getAgility() {
		return agility;
	}

	public void setIntelligent(float intelligent) {
		this.intelligent = intelligent + INTELLIGENT_DEFAULT;
		this.mana = this.intelligent * 10;
	}

	public void revoverHP() {
		if (!timeRecoverHP.checkValid() || this.getHP() <= 0)
			return;
		this.hitPoints = hitPoints + HPps;
		timeRecoverHP.schedule();
	}
	
	public void setCoolDownRecoverHP(long delay) {
		if (timeRecoverHP == null)
			timeRecoverHP = new MinisterCoolDown(delay);
		else 
			timeRecoverHP.setDelay(delay);
	}
	
	
	public float getIntelligent() {
		return intelligent;
	}

	public void setAttackBasic() {
		
	}

	protected class MinisterCoolDown {
		boolean valid = true;
		long delay;
		Timer timer;
		
		MinisterCoolDown(long delay) {
			this.delay = delay;
			timer = new Timer();
		}
		
		public void setDelay(long delay) {
			this.delay = delay;
		}
		
		public boolean checkValid() {
			return valid;
		}
		
		public void schedule() {
			valid = false;
			timer.schedule(new Task(), delay);
		}
		
		private class Task extends TimerTask {

			@Override
			public void run() {
				valid = true;
			}
		}
		
	}
	
}
